package exam;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Tests the answer to the second tree question.
 * The text of the question is as follows:
 * "Given a Huffman tree and a List<Integer> containing the path to a node as 0s and 1s, 
 *  find and return the corresponding leaf node."
 * 
 * @author Branden Ogata
 *
 */

public class TestTreeA01 extends Tester
{
  public static void main(String[] args)
  {
    final double POINTS = getPoints(args);
    
    List<HuffmanNode<String>> nodes = new ArrayList<HuffmanNode<String>>();
    
    for (int i = 0; i < 5; i++)
    {
      nodes.add(new HuffmanNode<String>());
    }
    
    nodes.set(4, new HuffmanNode<String>("C", 1));
    nodes.set(3, new HuffmanNode<String>("B", 1));
    nodes.set(2, new HuffmanNode<String>(nodes.get(3), nodes.get(4)));
    nodes.set(1, new HuffmanNode<String>("K", 2));
    nodes.set(0, new HuffmanNode<String>(nodes.get(1), nodes.get(2)));
    
    List<Integer> path = new LinkedList<Integer>();
    
    path.add(0);
    System.out.println(test(Category.EQUALS, "getNode with [0]", 
                            nodes.get(1), TreeA01.getNode(nodes.get(0), path), 
                            percentageToPoints(THIRD, POINTS)));
    path.clear();
    
    path.add(1);
    path.add(0);
    System.out.println(test(Category.EQUALS, "getNode with [1, 0]", 
                            nodes.get(3), TreeA01.getNode(nodes.get(0), path), 
                            percentageToPoints(THIRD, POINTS)));
    path.clear();
    
    path.add(1);
    path.add(1);
    System.out.println(test(Category.EQUALS, "getNode with [1, 1]", 
                            nodes.get(4), TreeA01.getNode(nodes.get(0), path), 
                            percentageToPoints(THIRD, POINTS)));
    path.clear();
    
    System.out.format("[%.2f/%.2f]%n", getTotalPoints(), POINTS);
  }
}
